package com.yunfeng.aolin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yunfeng.aolin.dao.StampingProductionReportDAO;
import com.yunfeng.aolin.entity.StampingProductionReport;
import com.yunfeng.aolin.service.StampingProductionReportService;
import com.yunfeng.common.util.Page;
import com.yunfeng.common.util.PageUtils;

@Service
@Transactional
public class StampingProductionReportServiceImpl implements
		StampingProductionReportService {

	@Autowired
	private StampingProductionReportDAO stampingProductionReportDAO;

	/**
	 * @param id
	 * @return
	 * @see com.yunfeng.aolin.service.StampingProductionReportService#get(java.lang.Long)
	 */
	@Override
	public StampingProductionReport get(Long id) {
		return stampingProductionReportDAO.findOne(id);
	}

	/**
	 * @param stampingProductionReport
	 * @see com.yunfeng.aolin.service.StampingProductionReportService#saveOrUpdate(com.yunfeng.aolin.entity.StampingProductionReport)
	 */
	@Override
	public void saveOrUpdate(StampingProductionReport stampingProductionReport) {
		stampingProductionReportDAO.save(stampingProductionReport);
	}

	/**
	 * @param id
	 * @see com.yunfeng.aolin.service.StampingProductionReportService#delete(java.lang.Long)
	 */
	@Override
	public void delete(Long id) {
		stampingProductionReportDAO.delete(id);
	}

	@Override
	public List<StampingProductionReport> findAll() {
		// TODO Auto-generated method stub
		return stampingProductionReportDAO.findAll();
	}

	/**
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.StampingProductionReportService#findAll(com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<StampingProductionReport> findAll(Page page) {
		org.springframework.data.domain.Page<StampingProductionReport> springDataPage = stampingProductionReportDAO
				.findAll(PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * @param page
	 * @param liaohao
	 * @return
	 * @see com.yunfeng.aolin.service.StampingProductionReportService#findByLiaohao(com.ketayao.ketacustom.util.dwz.Page,
	 *      java.lang.String)
	 */
	@Override
	public List<StampingProductionReport> findByLiaohao(Page page,
			String liaohao) {
		org.springframework.data.domain.Page<StampingProductionReport> springDataPage = stampingProductionReportDAO
				.findByLiaohaoContaining(liaohao,
						PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * 
	 * @param specification
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.StampingProductionReportService#findByExample(org.springframework.data.jpa.domain.Specification,
	 *      com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<StampingProductionReport> findByExample(
			Specification<StampingProductionReport> specification, Page page) {
		org.springframework.data.domain.Page<StampingProductionReport> springDataPage = stampingProductionReportDAO
				.findAll(specification, PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}
}
